package windowsevent;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ActionListenerTest extends JFrame implements ActionListener {

	JLabel jl;
	public ActionListenerTest( ) {
		setSize(300, 300);
		Container c = getContentPane();
		c.setLayout(new FlowLayout());
		JButton jb1 = new JButton("Ok");
		JButton jb2 = new JButton("Cancel");
		jl = new JLabel("Hello");
		c.add(jb1);
		c.add(jb2);
		c.add(jl);
		jb1.addActionListener(this);
		jb2.addActionListener(this);
	}
	@Override
	public void actionPerformed(ActionEvent ae) {
		if("Ok".equals(ae.getActionCommand().toString())) {
			jl.setText("Ok");
		}
		if("Cancel".equals(ae.getActionCommand().toString())) {
			jl.setText("Cancel");
		}
		
	}
	public static void main(String[] args) {
		ActionListenerTest action = new ActionListenerTest();
		action.setVisible(true);
	}

}
